package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.DealDetailBean;
import com.yiwei.hdb.api.callback.FundManageContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class FundManageRequest extends BaseRequest<FundManageContract.View> implements FundManageContract.Presenter<FundManageContract.View> {

    public static FundManageRequest create() {
        return new FundManageRequest();
    }


    @Override
    public void getDealDetailInfo(int type, int pageIndex, int pageSize) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        DealDetailBean bean = new DealDetailBean();
        bean.page = pageIndex;
        bean.pagesize = pageSize;
        Api.api_service.getDealDetailInfo(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getDealDetailInfoSuccess(type,pageIndex,result);
                });
    }

    @Override
    public void getBankList() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getBankList().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getBankListSuccess(result);
                });
    }

    @Override
    public void getBankRealname(int type) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getBankRealname().compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.getStatus() ==1) {
                        mView.getBankRealnameSuccess(type,result);
                    } else {
                        mView.getBankRealnameFail(result.getMsg());
                    }
                });
    }
}
